package edu.neumont.App;

import edu.neumont.entities.Entities;
import edu.neumont.entities.Network;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;

public class SettingsActivity extends Activity{
	private EditText nameInput;
	TextView portView, ipView, localhostTextView, errorView;
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.settings);
		
		
		nameInput = new EditText(this);
		portView = (TextView)findViewById(R.id.portTextView);
		portView.setText("" + Entities.network.getPort());
		ipView = (TextView)findViewById(R.id.ipTextView);
		ipView.setText(Entities.network.getIp());
		localhostTextView = (TextView)findViewById(R.id.ipInput);
		
		errorView = (TextView)findViewById(R.id.errorView);
		
		Button b = (Button)findViewById(R.id.connectButton);
		b.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				new AlertDialog.Builder(SettingsActivity.this)
				.setTitle("Name")
				.setMessage("Please name your device")
				.setView(nameInput)
				.setPositiveButton("OK", new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int which) {
						if(localhostTextView.getText().toString() != null && !localhostTextView.getText().toString().equals(""))
							Entities.network.setIp(localhostTextView.getText().toString());
						//errorView.setText(Entities.network.connect(nameInput.getText().toString()));
					}
				}).show();
			}
		});
	}
	
	

}
